package com.gjt.URI_URL;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.sql.SQLOutput;

/**
 * Created with Intel IDEA.
 * URLEncoder: .点 , *乘号 , _下划线 不能转换；最常见的用法是准备查询字符串，从而与使用GET方法的服务器端程序通信
 *
 * @Auther: gjt
 * @Date: 2024/3/22 20:21
 */
public class UrlEncode {
    public static void main(String[] args) throws UnsupportedEncodingException {

        /**
         * 对  https://www.google.com/search?hl=en&as_q=Java&as_epq=I/O URL进行编码
         */
        String query = URLEncoder.encode("https://www.google.com/search?hl=en&as_q=Java&as_epq=I/O");
        System.out.println("没有处理直接编码"+query);

        String url= "https://www.google.com/search?";
        QueryString queryString = new QueryString();
        queryString.add("hl","en");
        queryString.add("as_q","Java");
        queryString.add("as_epq","I/O");
        String query1 = queryString.getQuery();
        query1 = url+ query1;
        System.out.println("使用键值对后"+query1);
    }


    private  static void test(){
        try{

            String encode = URLEncoder.encode(".=& *%+/:~()   __","UTF-8");
            System.out.println(encode);
        }catch (UnsupportedEncodingException e){
            e.printStackTrace();
        }
    }

}
